package cn.iocoder.yudao.module.bpm.message.rocketmq;

import cn.iocoder.yudao.framework.mq.rocketmq.api.producer.service.ProducerMQService;
import cn.iocoder.yudao.module.bpm.message.ProcessInstanceMessage;
import cn.iocoder.yudao.module.bpm.message.dto.*;
import cn.iocoder.yudao.module.bpm.message.rocketmq.dto.*;
import cn.iocoder.yudao.module.bpm.message.consts.ProcessInstanceStreamKey;
import lombok.extern.log4j.Log4j2;

@Log4j2
public class RocketMqProcessInstanceMessage implements ProcessInstanceMessage {

    private final ProducerMQService rocketMQService;

    public RocketMqProcessInstanceMessage(ProducerMQService rocketMQService) {
        this.rocketMQService = rocketMQService;
    }
    @Override
    public void onProcessInstanceCleanMsg(BpmProcessInstanceCancelledMessage bpmProcessInstanceCancelledMessage) {

        RocketMqBpmProcessInstanceCancelledMessage msg = new RocketMqBpmProcessInstanceCancelledMessage();
        msg.setBpmProcessMessage(bpmProcessInstanceCancelledMessage);
        rocketMQService.sendMessage(ProcessInstanceStreamKey.PROCESS_INSTANCE_CLEAN_MSG_STREAM, msg);
    }

    @Override
    public void onProcessInstanceFinishedMsg(BpmProcessInstanceApproveMessage bpmProcessInstanceApproveMessage) {
        RocketMqBpmProcessInstanceApproveMessage msg = new RocketMqBpmProcessInstanceApproveMessage();
        msg.setBpmProcessMessage(bpmProcessInstanceApproveMessage);
        rocketMQService.sendMessage(ProcessInstanceStreamKey.PROCESS_INSTANCE_FINISHED_MSG_STREAM, msg);
    }

    @Override
    public void onProcessInstanceRejectMsg(BpmProcessInstanceRejectMessage bpmProcessInstanceRejectMessage) {
        RocketMqBpmProcessInstanceRejectMessage msg = new RocketMqBpmProcessInstanceRejectMessage();
        msg.setBpmProcessMessage(bpmProcessInstanceRejectMessage);
        rocketMQService.sendMessage(ProcessInstanceStreamKey.PROCESS_INSTANCE_REJECT_MSG_STREAM, msg);
    }

    @Override
    public void onProcessInstanceCreatedMsg(BpmProcessInstanceCreatedMessage bpmProcessInstanceCreatedMessage) {
        RocketMqBpmProcessInstanceCreatedMessage msg = new RocketMqBpmProcessInstanceCreatedMessage();
        msg.setBpmProcessMessage(bpmProcessInstanceCreatedMessage);
        rocketMQService.sendMessage(ProcessInstanceStreamKey.PROCESS_INSTANCE_CREATED_MSG_STREAM, msg);
    }

    @Override
    public void onProcessInstanceStartedMsg(BpmProcessInstanceStartedMessage bpmProcessInstanceStartedMessage) {
        RocketMqBpmProcessInstanceStartedMessage msg = new RocketMqBpmProcessInstanceStartedMessage();
        msg.setBpmProcessMessage(bpmProcessInstanceStartedMessage);
        rocketMQService.sendMessage(ProcessInstanceStreamKey.PROCESS_INSTANCE_STARTED_MSG_STREAM,msg);
    }
}
